package plugins

import (
	"fmt"
	"io/fs"
	"os"
)

type StartPlugin struct {
	BasePlugin
}

func (self *StartPlugin) Run() (err error) {
	step := self.Steps[self.Index]

	self.Running()
	prefix := fmt.Sprintf("%03d-%s", self.Index, step.Name)

	err = os.WriteFile(fmt.Sprintf("%s.input.txt", prefix), []byte(step.Input), fs.ModePerm)
	if err != nil {
		panic(err)
	}

	var output = step.Input

	err = os.WriteFile(fmt.Sprintf("%s.output.txt", prefix), []byte(output), fs.ModePerm)
	if err != nil {
		panic(err)
	}

	self.UpdateOutput(output)
	self.Finish()
	return nil
}
